<template>
    <div class="mainDiv">
        <el-row :gutter="20" class="rowHead">
            <el-col :span="16" id="el-col-16">
                <el-tag type="success">筛选：</el-tag>
                <el-date-picker v-model="searchinfo.times" type="daterange" align="right" placeholder="选择日期范围" :picker-options="pickerOptions2" @change="getList">
                </el-date-picker>
                <el-select v-model="searchinfo.ordertype" @change="getList">
                    <el-option :key="0" label="请选择单据类型" :value="0"></el-option>
                    <el-option :key="1" label="开卡" :value="1"></el-option>
                    <el-option :key="2" label="开单" :value="2"></el-option>
                    <el-option :key="3" label="充值" :value="3"></el-option>
                </el-select>
                <el-select v-model="searchinfo.status" @change="getList">
                    <el-option label="请选择状态" :value="0"></el-option>
                    <el-option label="未分配" :value="1"></el-option>
                    <el-option label="已分配" :value="2"></el-option>
                </el-select>     
            </el-col>
            <el-col :span="8" class="flex_center">
                   <el-input placeholder="搜索顾客姓名" v-model="searchinfo.search" @keyup.enter.native="getList">
                       <i slot="suffix" class="el-icon-search" style="line-height: 40px;width: 25px;cursor: pointer;" @click="getList"></i>
                   </el-input>
                    <el-button type="primary" @click="getList" style="margin-left: 5px" icon="h-shuaxin1">刷新列表</el-button>
            </el-col>
        </el-row>
        <el-table :data="list" :stripe="true" height="100%">
            <!-- <el-table-column prop="id" label="ID" width="80"></el-table-column> -->
            <el-table-column prop="order_sn" label="单号" width="170"></el-table-column>
            <el-table-column prop="name" label="顾客姓名">
                <template slot-scope="scope">
                    <span @click="openGuestPage(scope.row.guestid)" style="cursor:pointer;color:#f50">{{scope.row.name}}</span>
                </template>
            </el-table-column>
            <el-table-column prop="ordertype" label="出入类型">
                <template slot-scope="scope">
                    <Tags :typeValue="scope.row.ordertype" typeName="orderType"></Tags>
                </template>
            </el-table-column>
            <el-table-column prop="recemoney" label="现金业绩"></el-table-column>
            <el-table-column prop="cardreduce" label="卡耗业绩">
                <template slot-scope="scope">
                    {{scope.row.cardreduce + scope.row.usebalance}}
                </template>
            </el-table-column>
            <el-table-column prop="addtime" label="开单日期" show-overflow-tooltip>
                <template slot-scope="scope">{{scope.row.addtime|hourTime}}</template>
            </el-table-column>
            <el-table-column prop="status" label="状态">
                <template slot-scope="scope">
                    <Tags :typeValue="scope.row.status" typeName="orderStatus" :style="{color: '#fff'}"></Tags>
                </template>
            </el-table-column>
            <el-table-column label="操作">
                <template slot-scope="scope">
                    <el-tooltip content="分配业绩" placement="left" :open-delay="800" v-qx="quanxian.allot" v-if="scope.row.status == 1">
                        <el-button icon="el-icon-h-bumen" type="warning" size="mini" @click="fenpei(scope.row)"></el-button>
                    </el-tooltip>
                    <el-button-group v-else>
                        <el-tooltip content="查看" placement="left" :open-delay="800" v-qx="quanxian.look">
                            <el-button type="primary" icon="el-icon-h-chakan" size="mini" @click="fenpei(scope.row)"></el-button>
                        </el-tooltip>
                        <el-tooltip content="撤销分配" placement="left" :open-delay="800" v-qx="quanxian.chexiao">
                            <el-button type="danger" icon="el-icon-h-qiyong" size="mini" @click="chexiao(scope.row)"></el-button>
                        </el-tooltip>
                    </el-button-group>
                </template>
            </el-table-column>
        </el-table>
        <div class="block center bg-light">
            <el-pagination @size-change="sizeChange" @current-change="currentChange" :page-sizes="[15, 30, 50, 100]" :page-size="searchinfo.pageSize" layout="total, sizes, prev, pager, next, jumper" :total="total">
            </el-pagination>
        </div>
    </div>
</template>
<script>
import C from '@/common/common.js'
import P from '@/service/shop/popup.js'
import Guest from '@/service/shop/guest.js'
import Tags from '@/components/orderTags.vue'

export default {
  name: 'checkList',
  data () {
    return {
      list: [],
      total: 0,
      searchinfo: {
        currentPage: 1,
        pageSize: 15,
        search: '',
        ordertype: 0,
        status: 0,
        times: [new Date(), new Date()]
      },
      quanxian: {
        allot: 'allot_allot',
        look: 'allot_look',
        chexiao: 'allot_chexiao'
      },
      pickerOptions2: {
        shortcuts: [{
          text: '最近一周',
          onClick (picker) {
            const end = new Date()
            const start = new Date()
            start.setTime(start.getTime() - 3600 * 1000 * 24 * 7)
            picker.$emit('pick', [start, end])
          }
        }, {
          text: '最近一个月',
          onClick (picker) {
            const end = new Date()
            const start = new Date()
            start.setTime(start.getTime() - 3600 * 1000 * 24 * 30)
            picker.$emit('pick', [start, end])
          }
        }, {
          text: '最近三个月',
          onClick (picker) {
            const end = new Date()
            const start = new Date()
            start.setTime(start.getTime() - 3600 * 1000 * 24 * 90)
            picker.$emit('pick', [start, end])
          }
        }]
      }
    }
  },
  methods: {
    // 分配
    fenpei: async function (row) {
      await P.showOrderPopup({ id: row.id, status: row.status, ordertype: row.ordertype })
      this.getList()
    },
    sizeChange: function (val) {
      this.searchinfo.pageSize = val
      this.getList()
    },
    currentChange: function (val) {
      this.searchinfo.currentPage = val
      this.getList()
    },
    getList: async function () {
      let data = await C.ajax('/shop/kaidancheck/kaidanlist', { searchinfo: JSON.stringify(this.searchinfo) }, 'post')
      if (data) {
        this.list = data.data
        this.total = data.count
      }
    },
    chexiao: async function (row) {
      C.confirm('确定要撤销吗？', async index => {
        let data = await C.ajax('/shop/kaidancheck/fanfenpeiticheng', { id: row.id }, 'post')
        if (data) {
          C.success(data.data.info)
          this.getList()
        }
      })
    },
    openGuestPage (id) {
      Guest.openGuestPage(id)
    }
  },
  mounted: function () {
    this.getList()
  },
  components: { Tags }
}
</script>